<?php

require_once './core/p_pre.php';
process($db, $userId, $deviceId);
require_once './core/p_post.php';

function process(&$db, $userId, $deviceId) {
	require_once './core/dataset.php';
	$keyPage;
	if ( param('v') == 'm' ) {
		$keyPage = 'key_m.php';
	} else {
		$keyPage = 'key_d.php';
	}
	
?>

<div class="contentTitle">Data Set Category</div><br/>

<div style="text-align: left;">



<h3>By Kingdom</h3>
<ul data-role="listview">

<?php 

	$sql = "SELECT distinct kingdom, count(*) cnt 
		FROM key_data 
		WHERE Length (dataDir) > 0
		group by kingdom order by kingdom ";
	
	$result =& $db->doQuery($sql);
	if ( $result ) {		
		while($row = mysql_fetch_array($result)){
			$kingdom = $row['kingdom'];
			$url = "javascript:ULoader.loadPage('php/dataSet.php?v=d&kingdom=".$kingdom
			 ."')";
?>
<li><a href="<?php echo $url;?>"><?php echo $kingdom;?><span class="ui-li-count"><?php echo $row['cnt'];?></span></a></li>

<?php 
		}
	}
?>
</ul>
<br/><br/>



<h3>By Continent</h3>
<ul data-role="listview">

<?php 

	$sql = "SELECT distinct continent, count(*) cnt 
		FROM key_data 
		WHERE Length (dataDir) > 0
		group by continent order by continent ";
	
	$result =& $db->doQuery($sql);
	if ( $result ) {		
		while($row = mysql_fetch_array($result)){
			$continent = $row['continent'];
			$url = "javascript:ULoader.loadPage('php/dataSet.php?v=d&continent=".$continent
			 ."')";
?>
<li><a href="<?php echo $url;?>"><?php echo $continent;?><span class="ui-li-count"><?php echo $row['cnt'];?></span></a></li>

<?php 
		}
	}
?>
</ul>
<br/><br/>



</div>

<?php } ?>
